package cn.amossun.starter.event.handler;

import cn.hutool.core.util.StrUtil;
import cn.amossun.starter.event.common.Constants;
import cn.amossun.starter.event.enums.ExchangeTypeEnum;
import cn.amossun.starter.event.exception.EventConfigException;

public interface EventContextHolder extends ListenerHolder, PublisherHolder, MulticasterHolder {

    default String getDefaultExchangeName(boolean defaultTopicExchange, boolean defaultHeadersExchange) {
        String defaultExchangeName = defaultTopicExchange ? Constants.EVENT_TOPIC_EXCHANGE :
                (defaultHeadersExchange ? Constants.EVENT_HEADER_EXCHANGE : null);

        if(StrUtil.isEmpty(defaultExchangeName)) {
            throw new EventConfigException("missing default 'Exchange' config");
        }
        return defaultExchangeName;
    }

    default ExchangeTypeEnum getDefaultExchangeTypeEnum(boolean defaultTopicExchange, boolean defaultHeadersExchange) {
        ExchangeTypeEnum exchangeTypeEnum = defaultTopicExchange ? ExchangeTypeEnum.TOPIC :
                (defaultHeadersExchange ? ExchangeTypeEnum.HEADERS : null);

        if(exchangeTypeEnum == null) {
            throw new EventConfigException("missing default 'Exchange' config");
        }
        return exchangeTypeEnum;
    }

}
